<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="cart-decrease icon-remove_circle_outline" v-show="this.food.count > 0" @click="decrease"></div>
    </transition>
    <transition name="move">
      <div class="cart-count" v-show="this.food.count > 0">{{this.food.count}}</div>
    </transition>
    <div class="cart-add icon-add_circle" @click="add"></div>
  </div>
</template>

<script type="text/ecmascript-6">
  import Vue from 'vue';

  export default{
    props: {
      food: {
        type: Object
      }
    },
    created: function () {
    },
    methods: {
      add: function () {
        if (!event._constructed) {
          return;
        }
        if (!this.food.count) {
          Vue.set(this.food, 'count', 1);
        } else {
          this.food.count++;
        }
        this.$root.eventHub.$emit('cart-add', event.target);
      },
      decrease: function () {
        if (!event._constructed) {
          return;
        }
        if (!this.food.count) {
          Vue.set(this.food, 'count', 1);
        } else {
          this.food.count--;
        }
      }
    }
  };
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .cartcontrol
    font-size: 0
    .cart-decrease, .cart-count, .cart-add
      display: inline-block
    .cart-decrease, .cart-add
      font-size: 24px
      color: #00a0dc
      padding: 6px
    .move-enter-active
      animation: roll-in .4s
    .move-leave-active
      animation: roll-out .4s
    @keyframes roll-in {
      0% {
        transform: rotate(0) translate3D(30px, 0, 0)
        opacity: 0
      }
      100% {
        transform: rotate(180deg)
        opacity: 1
      }
    }
    @keyframes roll-out {
      0% {
        transform: rotate(180deg)
        opacity: 1
      }
      100% {
        transform: rotate(0) translate3D(30px, 0, 0)
        opacity: 0
      }
    }
    .cart-count
      font-size: 10px
      vertical-align: top
      line-height: 24px
      color: #93999f
      padding: 6px 0
</style>
